<template>
  <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <!-- 内容组件 -->
      <el-form :model="dialogModel" ref="addMenuForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="name" label="菜单名称">
          <el-input v-model="dialogModel.name" clearable></el-input>
        </el-form-item>
        <el-form-item prop="code" label="菜单识别码">
          <el-input v-model="dialogModel.code" clearable></el-input>
        </el-form-item>
        <el-form-item prop="nodeType" label="菜单类型">
          <!-- <el-input v-model="dialogModel.nodeType" clearable></el-input> -->
          <el-select v-model="dialogModel.nodeType" clearable style="width: 100%" placeholder="Select">
            <el-option label="文件夹" :value="1" />
            <el-option label="路由菜单" :value="2" />
            <el-option label="菜单按钮" :value="3" />
          </el-select>
        </el-form-item>
        <el-form-item prop="parentId" label="父级ID">
          <el-input v-model="dialogModel.parentId" type="number" clearable></el-input>
        </el-form-item>
        <el-form-item prop="nodeIcon" label="图标">
          <!-- <el-input v-model="dialogModel.nodeIcon" clearable></el-input> -->
          <el-select v-model="dialogModel.nodeIcon" style="width: 100%" popper-class="custom-select">
            <template #prefix>
              <span>
                 <svg-icon :name="dialogModel.nodeIcon?dialogModel.nodeIcon:'Appro'" />
              </span>
            </template>
            <el-option v-for="svg in svgPath" :key="svg" :value="svg" >
              <svg-icon :name="svg" />
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="router" label="页面路由">
          <el-input v-model="dialogModel.router" clearable></el-input>
        </el-form-item>
        <el-form-item prop="sort" label="菜单排序">
          <el-input v-model="dialogModel.sort" clearable></el-input>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';
import { ElForm } from 'element-plus'
import { EditType, Title } from '@/type/BaseEnum';
import menuModel from '@/composables/03organization/04menu/menuModel'
const req = import.meta.glob('@/assets/svg/*.svg')
const svgPath = ref<any>([])
for (const path in req) {
  svgPath.value.push(path.split('/').pop()?.split('.')[0])
}

// 使用
const addMenuForm = ref<InstanceType<typeof ElForm>>()
const emit = defineEmits(['save'])
const { dialog, onClose, onShow } = useDialog()
const { global, proxy } = useInstance();
const { rules, dialogModel } = menuModel()
// 父级数据
const props = defineProps({
  fileType: {
    type: [String, Number],
    default: 0
  }
})
// 保存
const confirm = () => {
  addMenuForm?.value?.validate((isOk) => {
    if (isOk) {
      console.log('数据校验');
      emit('save', dialogModel)
      onClose()
    }
  })
}
const show = (type: string, row?: any) => {
  console.log('show');
  dialog.width = 650
  dialog.height = 370
  dialog.title = type == EditType.ADD ? Title.ADD : Title.EDIT
  onShow()
  global.$resetForm(addMenuForm.value, dialogModel)
  if (type === EditType.EDIT) {
    global.$objCopy(row, dialogModel)
  }
}
defineExpose({
  show
})
</script>
<style lang="scss">
.custom-select{
  //  width: 505px;
  .el-scrollbar__view{
  display: flex;
  flex-wrap: wrap;
  width: 505px;
  .el-select-dropdown__item{
    padding: 0 20px 0 20px;
  }
}
}


</style>
<style scoped lang='scss'>

</style>